import Cookies from 'js-cookie'
export default({ app }) => {
  const wihteList = [
    '/', '/login', '/signUp', '/signUp/inputInfo',
    '/signUp/signUpDone', '/home/myShoppingCart',
    '/goodsList', '/goodsDetail', '/successfullyAdd'
  ]
  app.router.beforeEach((to, from, next) => {
    if (wihteList.indexOf(to.path) !== -1) {
      return next()
    }
    // 获取token
    const tokenStr = Cookies.get('loginInfo')
    if (!tokenStr) {
      return next('/login')
    } else {
      next()
    }
  })
}
